package com.integrance.budgetapp.domain;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "EXPENSE")
public class Expense {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "expense_id", nullable = false, unique = true)
	private Long id;
	
	@ManyToOne(optional = false)
	@JoinColumn(name = "expense_category_id", nullable = false)	
	private ExpenseCategory expenseCategory;
	
	@Column(name = "label", length = 30, nullable = false)
	private String label;
	
	@Column(name = "amount", precision = 2) // TODO use precision or scale?
	private BigDecimal amount;
	
	@Column(name = "expense_timestamp")
	private Date timestamp;
	
	@ManyToMany(mappedBy = "expenses")
	private Set<Budget> budgets;
	
	public Expense() {
		
	}
		
	public Expense(String label, ExpenseCategory expenseCategory) {
		this.label = label;
		this.expenseCategory = expenseCategory;
	}


	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public ExpenseCategory getExpenseCategory() {
		return expenseCategory;
	}

	public void setCategory(ExpenseCategory category) {
		this.expenseCategory = category;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public Long getId() {
		return id;
	}

	private void setId(Long id) {
		this.id = id;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}	
	
	public Set<Budget> getBudgets() {
		return budgets;
	}
	
	public void setBudgets(Set<Budget> budgets) {
		this.budgets = budgets;
	}
}
